package com.auto.video.tv.model;

import android.content.Context;
import android.util.Log;

import com.auto.video.tv.presenter.OnVideoListener;
import com.xin.auto.lib.base.UsbHelper;

import java.util.ArrayList;
import java.util.List;

import me.jahnen.libaums.core.UsbMassStorageDevice;
import me.jahnen.libaums.core.fs.UsbFile;


/**
 * Created by demo on 2017/4/2 0002
 */
public class VideoModel implements IVideoModel{
    private static final String TAG = "VideoModel";

    private List<String> mVideoInfos = new ArrayList<>();

    //USB文件列表相关
    private ArrayList<UsbFile> usbList = new ArrayList<>();
    private UsbHelper mUsbHelper;

    @Override
    public void loadVideo(final Context context, UsbHelper usbHelper, final OnVideoListener listener) {
        mVideoInfos = new ArrayList<>();
        mUsbHelper = usbHelper;
        updateUsbFile(0); // 一般就一个
        listener.onSuccess(usbList);
    }

    /**
     * 更新 USB 文件列表
     */
    private void updateUsbFile(int position) {
        UsbMassStorageDevice[] usbMassStorageDevices = mUsbHelper.getDeviceList();
        Log.i(TAG, "updateUsbFile: " + usbMassStorageDevices.length);
        if (usbMassStorageDevices.length > 0) {
            //存在USB
            usbList.clear();
            usbList.addAll(mUsbHelper.readDevice(usbMassStorageDevices[position]));
        } else {
            Log.e("UsbTestActivity", "No Usb Device");
            usbList.clear();
        }
    }

}
